home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_apache2.idb / usr / freeware / apache2 / include / apr_uri.h.z / apr_uri.h
C/C++ Source or Header  |  2002-07-08  |  8KB  |  221 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * Portions of this software are based upon public domain software
  55.  * originally written at the National Center for Supercomputing Applications,
  56.  * University of Illinois, Urbana-Champaign.
  57.  */
  58.  
  59. /*
  60.  * apr_uri.h: External Interface of apr_uri.c
  61.  */
  62.  
  63. /**
  64.  * @file apr_uri.h
  65.  * @brief APR-UTIL URI Routines
  66.  */
  67.  
  68. #ifndef APR_URI_H
  69. #define APR_URI_H
  70.  
  71. #include "apu.h"
  72.  
  73. #include <apr_network_io.h>
  74.  
  75. #ifdef __cplusplus
  76. extern "C" {
  77. #endif
  78.  
  79. /**
  80.  * @defgroup APR_Util_URI URI
  81.  * @ingroup APR_Util
  82.  * @{
  83.  */
  84.  
  85. #define APR_URI_FTP_DEFAULT_PORT         21
  86. #define APR_URI_SSH_DEFAULT_PORT         22
  87. #define APR_URI_TELNET_DEFAULT_PORT      23
  88. #define APR_URI_GOPHER_DEFAULT_PORT      70
  89. #define APR_URI_HTTP_DEFAULT_PORT        80
  90. #define APR_URI_POP_DEFAULT_PORT        110
  91. #define APR_URI_NNTP_DEFAULT_PORT       119
  92. #define APR_URI_IMAP_DEFAULT_PORT       143
  93. #define APR_URI_PROSPERO_DEFAULT_PORT   191
  94. #define APR_URI_WAIS_DEFAULT_PORT       210
  95. #define APR_URI_LDAP_DEFAULT_PORT       389
  96. #define APR_URI_HTTPS_DEFAULT_PORT      443
  97. #define APR_URI_RTSP_DEFAULT_PORT       554
  98. #define APR_URI_SNEWS_DEFAULT_PORT      563
  99. #define APR_URI_ACAP_DEFAULT_PORT       674
  100. #define APR_URI_NFS_DEFAULT_PORT       2049
  101. #define APR_URI_TIP_DEFAULT_PORT       3372
  102. #define APR_URI_SIP_DEFAULT_PORT       5060
  103.  
  104. /** Flags passed to unparse_uri_components(): */
  105. /** suppress "scheme://user@site:port" */
  106. #define APR_URI_UNP_OMITSITEPART    (1U<<0)
  107. /** Just omit user */
  108. #define APR_URI_UNP_OMITUSER        (1U<<1)
  109. /** Just omit password */
  110. #define APR_URI_UNP_OMITPASSWORD    (1U<<2)
  111. /** omit "user:password@" part */
  112. #define APR_URI_UNP_OMITUSERINFO    (APR_URI_UNP_OMITUSER | \
  113.                                      APR_URI_UNP_OMITPASSWORD)
  114. /** Show plain text password (default: show XXXXXXXX) */
  115. #define APR_URI_UNP_REVEALPASSWORD  (1U<<3)
  116. /** Show "scheme://user@site:port" only */
  117. #define APR_URI_UNP_OMITPATHINFO    (1U<<4)
  118. /** Omit the "?queryarg" from the path */
  119. #define APR_URI_UNP_OMITQUERY       (1U<<5)
  120.  
  121. typedef struct apr_uri_t apr_uri_t;
  122.  
  123. /**
  124.  * A structure to encompass all of the fields in a uri
  125.  */
  126. struct apr_uri_t {
  127.     /** scheme ("http"/"ftp"/...) */
  128.     char *scheme;
  129.     /** combined [user[:password]@]host[:port] */
  130.     char *hostinfo;
  131.     /** user name, as in http://user:passwd@host:port/ */
  132.     char *user;
  133.     /** password, as in http://user:passwd@host:port/ */
  134.     char *password;
  135.     /** hostname from URI (or from Host: header) */
  136.     char *hostname;
  137.     /** port string (integer representation is in "port") */
  138.     char *port_str;
  139.     /** the request path (or "/" if only scheme://host was given) */
  140.     char *path;
  141.     /** Everything after a '?' in the path, if present */
  142.     char *query;
  143.     /** Trailing "#fragment" string, if present */
  144.     char *fragment;
  145.  
  146.     /** structure returned from gethostbyname() 
  147.      *  @defvar struct hostent *hostent */
  148.     struct hostent *hostent;
  149.  
  150.     /** The port number, numeric, valid only if port_str != NULL */
  151.     apr_port_t port;
  152.     
  153.     /** has the structure been initialized */
  154.     unsigned is_initialized:1;
  155.  
  156.     /** has the DNS been looked up yet */
  157.     unsigned dns_looked_up:1;
  158.     /** has the dns been resolved yet */
  159.     unsigned dns_resolved:1;
  160. };
  161.  
  162. /* apr_uri.c */
  163. /**
  164.  * Return the default port for a given scheme.  The schemes recognized are
  165.  * http, ftp, https, gopher, wais, nntp, snews, and prospero
  166.  * @param scheme_str The string that contains the current scheme
  167.  * @return The default port for this scheme
  168.  */ 
  169. APU_DECLARE(apr_port_t) apr_uri_default_port_for_scheme(const char *scheme_str);
  170.  
  171. /**
  172.  * Unparse a apr_uri_t structure to an URI string.  Optionally 
  173.  * suppress the password for security reasons.
  174.  * @param p The pool to allocate out of
  175.  * @param uptr All of the parts of the uri
  176.  * @param flags How to unparse the uri.  One of:
  177.  * <PRE>
  178.  *    APR_URI_UNP_OMITSITEPART        Suppress "scheme://user@site:port" 
  179.  *    APR_URI_UNP_OMITUSER            Just omit user 
  180.  *    APR_URI_UNP_OMITPASSWORD        Just omit password 
  181.  *    APR_URI_UNP_OMITUSERINFO        Omit "user:password@" part
  182.  *    APR_URI_UNP_REVEALPASSWORD      Show plain text password (default: show XXXXXXXX)
  183.  *    APR_URI_UNP_OMITPATHINFO        Show "scheme://user@site:port" only 
  184.  *    APR_URI_UNP_OMITQUERY           Omit "?queryarg" or "#fragment" 
  185.  * </PRE>
  186.  * @return The uri as a string
  187.  */
  188. APU_DECLARE(char *) apr_uri_unparse(apr_pool_t *p, 
  189.                                     const apr_uri_t *uptr,
  190.                                     unsigned flags);
  191.  
  192. /**
  193.  * Parse a given URI, fill in all supplied fields of a apr_uri_t
  194.  * structure. This eliminates the necessity of extracting host, port,
  195.  * path, query info repeatedly in the modules.
  196.  * @param p The pool to allocate out of
  197.  * @param uri The uri to parse
  198.  * @param uptr The apr_uri_t to fill out
  199.  * @return An HTTP status code
  200.  */
  201. APU_DECLARE(int) apr_uri_parse(apr_pool_t *p, const char *uri, 
  202.                                apr_uri_t *uptr);
  203.  
  204. /**
  205.  * Special case for CONNECT parsing: it comes with the hostinfo part only
  206.  * @param p The pool to allocate out of
  207.  * @param hostinfo The hostinfo string to parse
  208.  * @param uptr The apr_uri_t to fill out
  209.  * @return An HTTP status code
  210.  */
  211. APU_DECLARE(int) apr_uri_parse_hostinfo(apr_pool_t *p, 
  212.                                         const char *hostinfo, 
  213.                                         apr_uri_t *uptr);
  214.  
  215. /** @} */
  216. #ifdef __cplusplus
  217. }
  218. #endif
  219.  
  220. #endif /* APR_URI_H */
  221.